/**
 * lilang
 * MailAction.java
 * 2013-9-26下午2:13:10
 */
package com.cq.oa.web.pof.action;

import org.apache.log4j.Logger;

import oa.base.session.SessionManger;
import oa.base.util.Constants;
import oa.base.util.Page;
import oa.base.web.Action.BaseAction;

import com.cq.oa.domain.dto.MailDto;
import com.cq.oa.domain.pof.Mail;
import com.cq.oa.domain.pof.MailRecord;
import com.cq.oa.service.pof.MailService;

/**
 * @author lilang
 *
 */
public class PofMailAction extends BaseAction<Mail>{

	/**
	 * lilang
	 * 2013-9-26下午2:25:17
	 */
	private static final long serialVersionUID = -7440785461596750089L;
	
	protected static final  Logger logger = Logger.getLogger(PofMailAction.class);
	
	private MailService mailService;
	
	
	private String attrId;
	/**
	 * 邮箱类型
	 */
	private Long folderId;
	
	private Integer isRead;
	
	private MailDto mailDto;
	
	
	
	
	public MailDto getMailDto() {
		return mailDto;
	}



	public void setMailDto(MailDto mailDto) {
		this.mailDto = mailDto;
	}



	public Long getFolderId() {
		return folderId;
	}



	public void setFolderId(Long folderId) {
		this.folderId = folderId;
	}

	public Integer getIsRead() {
		return isRead;
	}

	public void setIsRead(Integer isRead) {
		this.isRead = isRead;
	}

	public String getAttrId() {
		return attrId;
	}

	public void setAttrId(String attrId) {
		this.attrId = attrId;
	}


	public MailService getMailService() {
		return mailService;
	}


	public void setMailService(MailService mailService) {
		this.mailService = mailService;
	}





	/* (non-Javadoc)
	 * @see oa.base.web.Action.BaseAction#getEntityClass()
	 */
	@Override
	protected Class<Mail> getEntityClass() {
		return Mail.class;
	}
	
	
	public String findByPage() throws Exception {
		filterMap.put("pofMailFolderSid", folderId);
		filterMap.put("readFlag", isRead);
		filterMap.put(Constants.WHERE_LIKE+"title", entity.getTitle());
		filterMap.put("ownerSid", SessionManger.getUserId());
		shortMap.put(Constants.ORDER_BY_DESC, "sendTime");
		Page<MailRecord> users = mailService.findByPageCord(filterMap,shortMap,getPageNo(), getPageSize());
		this.renderJsonSuccess(jsonUtils.getExtJson(users, new String[] {}));
		return JSON;
	}
	
	
	
	/**
	 * 写邮件
	 * @return
	 * lilang 
	 * 2013-10-9下午12:50:54
	 */
	public String send(){
		this.mailService.doSendMail(entity, attrId);
		return this.renderJsonSuccess();
	}
	
	/**
	 * 发件箱
	 * @return
	 * lilang 
	 * 2013-10-10上午9:15:43
	 */
	public String outbox(){
		return "outbox";
	}
	
	/**
	 * 收件箱
	 * @return
	 * lilang 
	 * 2013-10-10上午9:15:43
	 */
	public String inbox(){
		return "inbox";
	}

	/**
	 * 详情
	 * @return
	 * lilang 
	 * 2013-10-10下午3:09:42
	 */
	public String detail(){
		try {
			mailDto = this.mailService.detail(entity.getSid());
		} catch (Exception e) {
			logger.error(e);
		}
		return "detail";
	}
	/**
	 * 删除记录
	 * @return
	 * lilang 
	 * 2013-10-11上午10:41:15
	 */
	public String delete(){
		this.mailService.deleteRecord(entity.getSid());
		return this.renderJsonSuccess();
	}
	
	
	public String draw(){
		return "draw";
	}
}
